package com.gold.bullion.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.gold.bullion.activity.MainMenuCell;

public class ImageAdapter extends BaseAdapter
{
    Context context;
    
    int[] images;
    
    String[] imageInfo;
    
    public ImageAdapter(Context context, int[] images, String[] imageInfo)
    {
        super();
        this.context = context;
        this.images = images;
        this.imageInfo = imageInfo;
    }
    
    public int getCount()
    {
        // TODO Auto-generated method stub
        return images.length;
    }
    
    public Object getItem(int arg0)
    {
        // TODO Auto-generated method stub
        return arg0;
    }
    
    public long getItemId(int position)
    {
        // TODO Auto-generated method stub
        return position;
    }
    
    public View getView(int position, View convertView, ViewGroup parent)
    {
        
        ViewHolder holder = null;
        MainMenuCell mainMenu = null;
        if (convertView == null)
        {
            mainMenu = new MainMenuCell(context);
//            mainMenu.resize(64, 64);
            holder = new ViewHolder();
            holder.text = (TextView) mainMenu.getTextView();
            holder.icon = (ImageView) mainMenu.getImageView();
            convertView = mainMenu;
            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.text.setText(imageInfo[position]);
        holder.icon.setImageResource(images[position]);
       
        return convertView;
    }
    
    static class ViewHolder
    {
        TextView text;
        
        ImageView icon;
    }
    
}
